//
//  NSString+WordSize.m
//  digital_robot_demo
//
//  Created by xskj on 2024/8/29.
//

#import "NSString+WordSize.h"

@implementation NSString (WordSize)

- (CGFloat)calculateWidth:(UIFont *)fontName withHeight:(CGFloat)height{
    NSDictionary *dic = @{NSFontAttributeName:fontName};//指定字号
    CGRect rect = [self boundingRectWithSize:CGSizeMake(MAXFLOAT, height)/*计算高度要先指定高度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
    return rect.size.width;
}
- (CGFloat)calculateHeight:(UIFont *)fontName withWidth:(CGFloat)width{
    NSDictionary *dic = @{NSFontAttributeName:fontName};//指定字号
    CGRect rect = [self boundingRectWithSize:CGSizeMake(width, MAXFLOAT)/*计算高度要先指定宽度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
    return rect.size.height;
}


@end
